class AimBoxUI extends BaseComp{
    private item:eui.Group;
    private img_icon:eui.Image;
    private curList = [];
    private curIndex = 0;
    private timer:egret.Timer;
    private img_mask:eui.Rect;
    constructor()
    {
        super('AimBoxView')
    }

    public init()
    {
        this.curList = RoleCache.instance().curMiniList;
        this.timer = new egret.Timer(5000);
        let curData = this.curList[this.curIndex];
        this.img_icon.source = curData.icon;
        this.img_icon.width = this.img_icon.height = 110;
        this.img_icon.mask = this.img_mask;
        this.timer.start();
        EffectUtil.instance().shakeEffect(this);
    }

    public addEvent()
    {
        this.item.addEventListener(egret.TouchEvent.TOUCH_TAP, this.touchHandle, this);
        this.timer.addEventListener(egret.TimerEvent.TIMER, this.update, this);
    }

    protected update()
    {
        this.curIndex++;
        if(this.curIndex >= this.curList.length)
        {
            this.curIndex = 0;
        }
        this.updateIcon();
    }

    protected updateIcon()
    {
        let curData = this.curList[this.curIndex];
        if(curData)
        {
            this.img_icon.source = curData.icon;
            this.img_icon.width = this.img_icon.height = 110;
        }
    }

    public touchHandle()
    {
        let data = this.curList[this.curIndex];
        let appid  = data.appid;
        if(appid)
        WeChatgGameManager.instance().navigateToMiniProgram(appid);
    }

    public removeEvent()
    {
        this.item.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.touchHandle, this);
        this.timer.removeEventListener(egret.TimerEvent.TIMER, this.update, this);
    }

    public clear()
    {
        super.clear();
        EffectUtil.instance().StopEffect(this);
        this.curList = null;
        this.curIndex = null;
        this.timer.stop();
        this.timer = null;
    }
}

window['AimBoxUI'] = AimBoxUI;